package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.YcInde;
import com.ruoyi.system.domain.YcMeasures;
import com.ruoyi.system.domain.YcMeasures_v2;
import com.ruoyi.system.service.IYcMeasuresService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 油厂措施管理Controller
 * 
 * @author ruoyi
 * @date 2022-10-22
 */
@RestController
@RequestMapping("/system/measures")
public class YcMeasuresController extends BaseController
{
    @Autowired
    private IYcMeasuresService ycMeasuresService;

    /**
     * 查询油厂措施管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:measures:list')")
    @GetMapping("/list")
    public TableDataInfo list(YcMeasures ycMeasures)
    {
        startPage();
        List<YcMeasures> list = ycMeasuresService.selectYcMeasuresList(ycMeasures);
        return getDataTable(list);
    }

    /**
     * 查询更多油厂措施管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:measures:list')")
    @GetMapping("/listMore")
    public TableDataInfo listMore(YcMeasures_v2 ycMeasures_v2)
    {
        startPage();
        List<YcMeasures> list = ycMeasuresService.selectYcMeasuresListMore(ycMeasures_v2);
        return getDataTable(list);
    }
    /**
     * 查询更多油厂措施管理列表（管理页面专用）
     */
    @PreAuthorize("@ss.hasPermi('system:measures:list')")
    @GetMapping("/listMore1")
    public TableDataInfo listMore1(YcMeasures_v2 ycMeasures_v2)
    {
        startPage();
        List<YcMeasures> list = ycMeasuresService.selectYcMeasuresListMore1(ycMeasures_v2);
        return getDataTable(list);
    }



    /**
     * 查询更多油厂措施管理列表（admin）
     */
    @PreAuthorize("@ss.hasPermi('system:measures:list')")
    @GetMapping("/listMoreAdmin")
    public TableDataInfo listMoreAdmin(YcMeasures_v2 ycMeasures_v2)
    {
        startPage();
        List<YcMeasures> list = ycMeasuresService.selectYcMeasuresListMoreAdmin(ycMeasures_v2);
        return getDataTable(list);
    }

    /**
     * 导出油厂措施管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:measures:export')")
    @Log(title = "油厂措施管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YcMeasures ycMeasures)
    {
        List<YcMeasures> list = ycMeasuresService.selectYcMeasuresListUseExport(ycMeasures);
        ExcelUtil<YcMeasures> util = new ExcelUtil<YcMeasures>(YcMeasures.class);
        util.exportExcel(response, list, "油厂措施管理数据");
    }

    /**
     * 获取油厂措施管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:measures:query')")
    @GetMapping(value = "/{meaId}")
    public AjaxResult getInfo(@PathVariable("meaId") Long meaId)
    {
        return AjaxResult.success(ycMeasuresService.selectYcMeasuresByMeaId(meaId));
    }

    @GetMapping("selectYcMeasuresByDataId/{dataId}")
    public AjaxResult selectYcMeasuresByDataId(@PathVariable("dataId") Long dataId)
    {
        return AjaxResult.success(ycMeasuresService.selectYcMeasuresByDataId(dataId));
    }

    /**
     * 新增油厂措施管理
     */
    @PreAuthorize("@ss.hasPermi('system:measures:add')")
    @Log(title = "油厂措施管理", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody YcMeasures ycMeasures)
    {
        return toAjax(ycMeasuresService.insertYcMeasures(ycMeasures));
    }

    /**
     * 修改油厂措施管理
     */
    @PreAuthorize("@ss.hasPermi('system:measures:edit')")
    @Log(title = "油厂措施管理", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody YcMeasures ycMeasures)
    {
        return toAjax(ycMeasuresService.updateYcMeasures(ycMeasures));
    }

    /**
     * 批量修改油厂措施
     */
    @PreAuthorize("@ss.hasPermi('system:measures:edit')")
    @Log(title = "油厂措施管理", businessType = BusinessType.UPDATE)
    @GetMapping("/edits/{meaIds}")
    public AjaxResult edits(@PathVariable Long[] meaIds)
    {
        return toAjax(ycMeasuresService.updateYcMeasuresByMeaIds(meaIds));
    }


    /**
     * 删除油厂措施管理
     */
    @PreAuthorize("@ss.hasPermi('system:measures:remove')")
    @Log(title = "油厂措施管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{meaIds}")
    public AjaxResult remove(@PathVariable Long[] meaIds)
    {
        return toAjax(ycMeasuresService.deleteYcMeasuresByMeaIds(meaIds));
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<YcMeasures> util = new ExcelUtil<YcMeasures>(YcMeasures.class);
        util.importTemplateExcel(response, "油厂措施");
    }

    @Log(title = "油厂措施管理", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:measures:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<YcMeasures> util = new ExcelUtil<YcMeasures>(YcMeasures.class);
        List<YcMeasures> ycMeasuresList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = ycMeasuresService.importData(ycMeasuresList, updateSupport, operName);
        return AjaxResult.success(message);
    }
}

